/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package planspiel.panels.subpanels;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import planspiel.panels.GameScreen;
import admintool.imp03_data.IMP03_Candidate;
import admintool.imp03_data.IMP03_City;
import admintool.imp03_data.IMP03_Platform;
import admintool.imp03_data.IMP03_Skill;
/**
 *
 * @author Administrator
 */
public class GameContentCandidate extends JPanel{
  
	private static final long serialVersionUID = 1571753514921951893L;
	private GameScreen gameScreen = null;
    private IMP03_Candidate selectedCandidate = null;
    private Image image = null;
    
    /**
     * 
     * @param gameScreen
     */
    public GameContentCandidate(GameScreen gameScreen) {
        this.gameScreen = gameScreen;
        initDisplay();
        
        //Set Background Image
        try {
        	IMP03_Platform platform = this.gameScreen.getGame().getCurrentGameRoundController().getSelectedPlatform();
        	String imageName = "BackgroundCandidate.jpg";
        	if (platform.getPlatformName().toLowerCase().startsWith("facebook")) {
        		imageName = "BackgroundFacebook.jpg";
        	} else if (platform.getPlatformName().toLowerCase().startsWith("stepstone")) {
        		imageName = "BackgroundStepstone.jpg";
        	}
        	if (platform.getPlatformName().toLowerCase().startsWith("twitter")) {
        		imageName = "BackgroundTwitter.jpg";
        	}
        	if (platform.getPlatformName().toLowerCase().startsWith("xing")) {
        		imageName = "BackgroundXing.jpg";
        	}
            BufferedImage tmpImage = new BufferedImage(1000, 800, BufferedImage.TYPE_INT_RGB);
            tmpImage = ImageIO.read(this.getClass().getResourceAsStream("/planspiel/resources/" + imageName));
            this.image =  new ImageIcon(tmpImage.getScaledInstance(720, 580, Image.SCALE_SMOOTH)).getImage();
        } catch (Exception e) {
            e.printStackTrace();
        }         
    }

    /**
     * 
     * @return
     */
    public IMP03_Candidate getSelectedCandidate() {
        return selectedCandidate;
    }
    
    @Override
    protected void paintComponent(Graphics g) {
        g.drawImage(image, 0, 0, null);
        //super.paintComponent(g);
    }
    
    private void initDisplay(){
        
        final JComboBox cbCandidate = new JComboBox(IMP03_Candidate.getAllAvailableCandidatesForSpecificPlatform(gameScreen.getGame().getCurrentGameRoundController().getSelectedPlatform()).toArray());
        
        final JLabel label1 = new JLabel("Nachname: ");
        final JLabel label2 = new JLabel("Vorname: ");
        final JLabel label3 = new JLabel("Geschlecht: ");
        final JLabel label4 = new JLabel("Geburtsdatum: ");
        final JLabel label5 = new JLabel("PLZ: ");
        final JLabel label6 = new JLabel("Abschluss: ");
        final JLabel label7 = new JLabel("Fertigkeiten: ");
        final JLabel label8 = new JLabel("Erfahrung: ");
        
        
        this.setLayout(null);
        // Kandidaten-Auswahl linnks
        cbCandidate.setBounds(2, 180, 260, 25);
        int x = 200;
        int y = 300;
        int yoff = 20;
        int w = 100;
        int h = 12;
        // Labels im Ergebnisbereich
        label1.setBounds(x, y, w, h);
        y += yoff;
        label2.setBounds(x, y, w, h);
        y += yoff;
        label3.setBounds(x, y, w, h);
        y += yoff;
        label4.setBounds(x, y, w, h);
        y += yoff;
        label5.setBounds(x, y, w, h);
        y += yoff;
        label6.setBounds(x, y, w, h);
        y += yoff;
        label7.setBounds(x, y, w, 18);
        y += 25;
        label8.setBounds(x, y, w, 18);
        
        // Felder im Ergenisbereich
        final JLabel text1 = new JLabel();
        final JLabel text2 = new JLabel();
        final JLabel text3 = new JLabel();
        final JLabel date4 = new JLabel();
        final JLabel tmpCombo51 = new JLabel();
        final JLabel tmpLabel52 = new JLabel();
        final JLabel combo6 = new JLabel();
        final JComboBox skillCombo = new JComboBox();
        final JLabel skillLevel = new JLabel();
        final JComboBox combo8 = new JComboBox();
        
        x = 310;
        y = 300;
        w = 100;
        h = 12;
        text1.setBounds(x, y, w, h);
        y += yoff;
        text2.setBounds(x, y, w, h);
        y += yoff;
        text3.setBounds(x, y, w, h);
        y += yoff;
        date4.setBounds(x, y, w, h);
        y += yoff;
        tmpCombo51.setBounds(x, y, w, h);
        tmpLabel52.setBounds(x + 50, y, 200, h);
        y += yoff;
        combo6.setBounds(x, y, w, h);
        y += yoff;
        skillCombo.setBounds(x, y, w, 18);
        skillLevel.setBounds(x + 150, y, w, 18);
        y += 25;
        combo8.setBounds(x, y, 220, 18);
        
        this.add(cbCandidate);
        this.add(label1);
        this.add(label2);
        this.add(label3);
        this.add(label4);
        this.add(label5);
        this.add(label6);
        this.add(label7);
        this.add(label8);
        this.add(text1);
        this.add(text2);
        this.add(text3);
        this.add(date4);
        this.add(tmpCombo51);
        this.add(tmpLabel52);
        this.add(combo6);
        this.add(skillCombo);
        this.add(skillLevel);
        this.add(combo8);
        
        this.validate();
        
        cbCandidate.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                    selectedCandidate = (IMP03_Candidate)(cbCandidate.getSelectedItem());
                    

                    text1.setText(selectedCandidate.getLastName());
                    text2.setText(selectedCandidate.getFirstName());
                    text3.setText(selectedCandidate.getGender());
                    date4.setText(String.valueOf(selectedCandidate.getDateOfBirth()));
                    tmpCombo51.setText(selectedCandidate.getPLZ());
                    tmpLabel52.setText(IMP03_City.getSpecificCitiesFromDB(selectedCandidate.getPLZ()).getCityName());

                    combo6.setText(selectedCandidate.getQualification());

                    JComboBox tmpComboForModel = new JComboBox(selectedCandidate.getCandidateSkills().toArray());
                    skillCombo.setModel(tmpComboForModel.getModel());
                    skillCombo.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            skillLevel.setText("SkillLevel: " + ((IMP03_Skill)(skillCombo.getSelectedItem())).getSkillLevelForCandidate(selectedCandidate.getCandidateID()));
                        }
                    });
                    if(skillCombo.getItemCount() > 0){
                        skillCombo.setSelectedIndex(0);
                    }
                    skillCombo.setMaximumSize(new Dimension(1000, text1.getHeight()));
                    
                    tmpComboForModel = new JComboBox(selectedCandidate.getCandidateExperience().toArray());
                    combo8.setModel(tmpComboForModel.getModel());

            }
       
        });
        
        if(cbCandidate.getItemCount() > 0){
            cbCandidate.setSelectedIndex(0);
        }
    }
}